import { markRaw, Ref, createVNode, getCurrentInstance, render } from 'vue';
import Viewer from 'bpmn-js/lib/Viewer';
import modelerStore from '@wf/components/bpmnjs/store/modeler';
import type { BaseViewerOptions } from 'bpmn-js/lib/BaseViewer';

export default async function (
  designer: Ref<HTMLElement | null>,
  // modelerModules: ModulesAndModdles,
  // emit
) {
  const store = modelerStore();

  const options: BaseViewerOptions = {
    container: designer!.value as HTMLElement,
  };

  if (store.getModeler) {
    // 清除旧 modeler
    store.getModeler.destroy();
    await store.setModeler(undefined);
  }

  const viewer: Viewer = new Viewer(options);

  await store.setViewer(markRaw(viewer));
}